<?php

class M_excel_printables Extends MY_Model
{

	public function __contsruct()
	{
		parent::__contsruct();
	
	}
	
	public function get_all_student_profiles($column = FALSE,$grade_level = FALSE,$room_section = TRUE)
	{
		$column_values['student_profile'] = 'lastname,
											firstname,
											middlename,
											nickname,
											name_ext,
											gender,
											dob as date_of_birth,
											pob as place_of_birth,
											p.age,
											nationality,
											religion,
											contact_no,
											mobile_phone,
											email,
											present_address';
		$column_values['student_parent_profiles'] = 'fathername,
													father_mname,
													father_lname,
													father_nationality,
													father_occupation,
													father_office_num,
													father_contact_no,
													father_graduate_degree,
													father_income_bracket,
													mothername,
													mother_mname,
													mother_lname,
													mother_nationality,
													mother_occupation,
													mother_office_num,
													mother_contact_no,
													mother_graduate_degree,
													mother_income_bracket,
													step_father_name,
													step_father_mname,
													step_father_lname,
													step_father_citizenship,
													step_father_occup,
													step_father_office_tel,
													step_father_contact_no,
													step_father_graduate_degree,
													step_father_income_bracket,
													step_mother_name,
													step_mother_mname,
													step_mother_lname,
													step_mother_citizenship,
													step_mother_occup,
													step_mother_office_tel,
													step_mother_contact_no,
													step_mother_graduate_degree,
													step_mother_income_bracket';
		$column_values['student_guardian_profile'] = 'guardian_name,
													  guardian_mname,
													  guardian_lname,
													  guardian_citizenship,
													  guardian_visa,
													  guardian_occup,
													  guardian_office_tel,
													  guardian_contact_no';
		$column_values['student_family_history'] = 'parent_status,
													parent_status_how_long,
													parent_rights,
													concat(sibling_fname1,sibling_lname1) as siblingone,
													sibling_age1,
													concat(sibling_fname2,sibling_lname2) as siblingtwo,
													sibling_age2,
													concat(sibling_fname3,sibling_lname3) as siblingthree,
													sibling_age3,
													concat(sibling_fname4,sibling_lname4) as siblingfour,
													sibling_age4,
													concat(sibling_fname5,sibling_lname5) as siblingfive,
													sibling_age5,
													concat(sibling_fname6,sibling_lname6) as siblingsix,
													sibling_age6,
													child_pos,
													child_adopted,
													child_age_adopted,
													child_aware_adopted,
													mother_present_pregnant,
													mother_due_date,
													family_deaths,
													family_deaths_child_relation,
													family_accidents,
													family_accidents_child_relation,
													p.what,
													p.when,
													other_household_member1,
													other_household_age1,
													other_household_member2,
													other_household_age2,
													other_household_member3,
													other_household_age3,
													other_household_member4,
													other_household_age4,
													other_household_member5,
													other_household_age5,
													other_household_member6,
													other_household_age6,
													languages_spoken_at_home,
													family_activities,
													family_activities_frequent';
		$column_values['development_history'] = 'dhc_pregnancy_length,
												dhc_delivery_form,
												dhc_compications,
												dhc_sleep_time,
												dhc_wakup_time,
												dhc_sleeping_disturbance,
												dhc_sleeping_disturbance_what,
												dhc_child_own_room,
												dhc_room_shares_who,
												dhc_child_wet_bed,
												dhc_defect_growth,
												dhc_defect_specify,
												dhc_defect_when,
												dhc_defect_actions,
												dhc_speech_problems,
												dhc_speech_problem_what,
												dhc_speech_problem_when,
												dhc_speech_problem_actions,
												dhc_hearing_last_check,
												dhc_hearing_problems,
												dhc_hearing_problems_what,
												dhc_hearing_problems_when,
												dhc_hearing_problem_actions,
												dhc_vision_checked,
												dhc_sight_problem,
												dhc_sight_problems_what,
												dhc_hinder_learning_process';
		$column_values['cehh'] = 'ce_trauma_exp,
									ce_trauma_exp_what,
									ce_trauma_exp_age,
									ce_trauma_exp_reaction,
									ce_trauma_exp_affected,
									ce_special_fears,
									ce_special_fears_what,
									ce_special_fears_when,
									ce_special_fears_handle,
									hhc_past_illness,
									hhc_frequent_colds,
									hhc_frequent_headaches,
									hhc_frequent_stomachaches,
									hhc_dizziness,
									hhc_vomitting,
									hhc_major_injury,
									hhc_major_injury_specify,
									hhc_major_operations,
									hhc_major_operations_specify,
									hhc_diagnosed,
									hhc_diagnosed_specify,
									hhc_medication,
									hhc_alergic_med,
									hhc_general_eating,
									hhc_school_help_eating,
									hhc_food_restrictions';
		$column_values['discipline'] = 'd_method_of_discipline,
										d_handles_discipline,
										d_discipline_effective,
										d_discipline_rod,
										d_discipline_rod_why,
										d_teacher_use_rod,
										d_teacher_use_rod_why,
										d_suggest_discipline,
										d_school_help_discipline,
										d_provide_information';
		$column_values['foreign'] = 'f_ssp_status,
									f_visa_status,
									f_authorized_stay,
									f_passport_no,
									f_i_card_no,
									f_date_if_issue';
									
									
		
		if($column !== FALSE)
		{
			$x = count($column);
			for($y = 0;$y<$x;$y++)
			{
				$data[$y] = $column_values[$column[$y]];
			}
			
			$column = implode(',',$data);
			
			
			$sql = "SELECT s.section_name,r.name as room_name,l.level_desc,{$column}
					FROM profiles p
					LEFT JOIN enrollments e ON e.e_profile_id = p.profile_id
					LEFT JOIN levels l ON l.level_id = e.e_grade_level ";
			
			if($room_section == TRUE)
			{
				$sql .= "LEFT JOIN sections s ON s.id = e.e_section_id 
						 LEFT JOIN rooms r ON s.id = r.section_id";
			}
		
			
			$sql .=" WHERE e.verified = 1
					  AND e.e_ay_id = ?
					  AND e.e_archived = 0 ";
					  
			if($grade_level !== FALSE)
			{
				if(is_array($grade_level))
				{
					if(in_array('all',$grade_level))
					{
					
					}else{
						$gl = 'AND e.e_grade_level = '.implode(' OR e.e_grade_level = ',$grade_level);
						$sql .= "{$gl}";
					}
				}else{
					$sql .= "AND e.e_grade_level= {$grade_level}";
				}
			}
			
			$sql .= " ORDER BY e.e_grade_level,p.lastname";
			
			$result = $this->db->query($sql,array($this->c_sy->id));
			

			
			$TRUE = (object)array('status'=>TRUE,'result'=>$result->result(),'columns'=>'section_name,room_name,level_desc,'.$column);
			$FALSE = (object)array('status'=>FALSE);
			return $result->num_rows() >= 1 ? $TRUE : $FALSE;
		}else{
			return FALSE;
		}
	}
}